/*
 * BanBu_BroadcastTVC
 * @description 本文件提供附近广播和个人空间广播的ViewController
 * @package
 * @author 		***
 * @copyright
 * @version 		1.0
 * @description 本文件提供附近广播和个人空间广播的的ViewController
 */

#import "BanBu_BroadcastTVC.h"
#import "BanBu_DigiViewController.h"
#import "AppCommunicationManager.h"
#import "TKLoadingView.h"
#import "AppDataManager.h"
#import "BanBu_PictureAndVoice.h"
#import "BanBu_NavButton.h"
#import "BanBu_ImageView.h"
#import "LeveyTabBarController.h"
#import "BanBu_ThemeManager.h"
#import "BanBu_RefreshTime.h"
#import "BanBu_LocationManager.h"

#import "UIBadgeView.h"
#import "LeveyTabBarController.h"
#import "NSDictionary_JSONExtensions.h"
#import "BanBu_magicWordsCell.h"
@interface BanBu_BroadcastTVC ()

@end

NSInteger selectedRow;
NSInteger displayCell = -1;
@implementation BanBu_BroadcastTVC

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
    }
    return self;
}

-(void)dealloc
{
    [_dataArray release];
    _dataArray = nil;
    [AppComManager cancalHandlesForObject:self];
    if(!_useridBroad.length)
    {
        [segmentController release],segmentController = nil;
//        [imageDic release],imageDic = nil;
        [_player release],_player = nil;
        [listButton release],listButton = nil;
        [btn_return release],btn_return = nil;
        [hotKeyArr release],hotKeyArr = nil;
        [cacheArray release],cacheArray = nil;
        [_existDic release];_existDic = nil;
        [[NSNotificationCenter defaultCenter]removeObserver:self name:@"xiangqingAction" object:nil];
        [[NSNotificationCenter defaultCenter]removeObserver:self name:@"setFriendActionNum" object:nil];
    }
    [[NSNotificationCenter defaultCenter]removeObserver:self name:@"delete_Broadcast" object:nil];

    if(_player){
        [_player release],_player = nil;
    }
    [MyAppDataManager.friendDos removeAllObjects];
    [moreView release];moreView = nil;
    NSString *str = [NSString stringWithFormat:@"%@",self.tableView.observationInfo];
    if(str.length&&[str rangeOfString:@"contentOffset"].location != NSNotFound)
        [self.tableView removeObserver:self forKeyPath:@"contentOffset"];
    [super dealloc];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    if(search.text.length)
    {
        [self goSearchBroad:nil];
    }
    return YES;
}

-(void)buildHotKeyView
{
    int selectHotkey = 0;
    if (hotKeyArr.count>8)
    {
        srand((unsigned)time(0));
        selectHotkey = rand()%hotKeyArr.count;
    }
    search.text = [NSString stringWithFormat:@"#%@",[hotKeyArr objectAtIndex:selectHotkey]];
}

#pragma mark - 修改主题
-(void)changeTheme
{
    UIImage *backgroundImage = [ThemeManager getThemeImage:@"segmentTitle.png"];//[[ThemeManager getThemeImage:@"segmentTitle.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0)];
    
    [segmentController setBackgroundImage:backgroundImage];

}

#pragma mark - 初始化segment
- (void)setupSegmentedControl
{
    NSArray *titleArr = [NSArray arrayWithObjects:NSLocalizedString(@"friendShip4", nil),NSLocalizedString(@"friendShip2", nil), nil];
    UIImage *backgroundImage = [ThemeManager getThemeImage:@"segmentTitle.png"];//[[ThemeManager getThemeImage:@"segmentTitle.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0)];
    [segmentController setBackgroundImage:backgroundImage];
    //    [segmentController setContentEdgeInsets:UIEdgeInsetsMake(2.0, 2.0, 3.0, 2.0)];
    [segmentController setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleBottomMargin];
    
//    [segmentController setSeparatorImage:[UIImage imageNamed:@"segmented-separator.png"]];
    
    
    UIImage *buttonBackgroundImagePressed_left = [UIImage imageNamed:@"segmented-bg-pressed_left.png"];//[[UIImage imageNamed:@"segmented-bg-pressed_left.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0.0, 4.0, 0.0, 1.0)];
    UIImage *buttonBackgroundImagePressed_right = [UIImage imageNamed:@"segmented-bg-pressed_right.png"];
    // Button 1
    UIButton *buttonSocial = [[UIButton alloc] init];
    [buttonSocial setTitle:[titleArr objectAtIndex:0] forState:UIControlStateNormal];
    [buttonSocial setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [buttonSocial.titleLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:15.0]];
    //    [buttonSocial setTitleEdgeInsets:UIEdgeInsetsMake(0.0, 5.0, 0.0, 0.0)];
    [buttonSocial setBackgroundImage:buttonBackgroundImagePressed_left forState:UIControlStateHighlighted];
    [buttonSocial setBackgroundImage:buttonBackgroundImagePressed_left forState:UIControlStateSelected];
    [buttonSocial setBackgroundImage:buttonBackgroundImagePressed_left forState:(UIControlStateHighlighted|UIControlStateSelected)];
    
    
    // Button 2
    UIButton *buttonStar = [[UIButton alloc] init];
    [buttonStar setTitle:[titleArr objectAtIndex:1] forState:UIControlStateNormal];
    [buttonStar setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [buttonStar.titleLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:15.0]];
    //    [buttonStar setTitleEdgeInsets:UIEdgeInsetsMake(0.0, 5.0, 0.0, 0.0)];
    [buttonStar setBackgroundImage:buttonBackgroundImagePressed_right forState:UIControlStateHighlighted];
    [buttonStar setBackgroundImage:buttonBackgroundImagePressed_right forState:UIControlStateSelected];
    [buttonStar setBackgroundImage:buttonBackgroundImagePressed_right forState:(UIControlStateHighlighted|UIControlStateSelected)];
    
    [segmentController setButtonsArray:@[buttonSocial, buttonStar]];
    [buttonSocial release];
    [buttonStar release];
    [[self.navigationItem.titleView superview] bringSubviewToFront:self.navigationItem.titleView];
    self.navigationItem.titleView = segmentController;
    
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if(!_useridBroad.length)
    {
        [super scrollViewDidScroll:scrollView];
    }
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    if(!_useridBroad.length)
    {
        [super scrollViewDidEndDragging:scrollView willDecelerate:decelerate];
    }
}

-(void)updateBroadcastBadgeValue
{
    [MyAppDataManager modifyUserBaseDataWithKey:KeyUnReadDynamicNum andData:MyAppDataManager.unReadBroadInfor];
    
    NSMutableDictionary *badgeDic = [NSMutableDictionary dictionaryWithDictionary:MyAppDataManager.unReadBroadInfor];
    
    NSString *segmentBadgeValueFriend = [NSString stringWithFormat:@"%d",[[badgeDic valueForKey:@"h"] integerValue]+[[badgeDic valueForKey:@"g"] integerValue]];
    NSString *segmentBadgeValueMo     = [NSString stringWithFormat:@"%d",[[badgeDic valueForKey:@"z"] integerValue]];
    [self setSegmentBadgeValue:segmentBadgeValueFriend andMo:segmentBadgeValueMo];
    
    //    NSString *segmentBadgeValueMo  = [NSString stringWithFormat:@"%d",[badgeDic valueForKey:@""]]
    //
    //    NSString *tabBadgeValue = [NSString stringWithFormat:@"%d",[segmentBadgeValueFriend integerValue]+[[badgeDic valueForKey:@"z"] integerValue]];
    //    [self setTabBarBadgeValue:tabBadgeValue];
    NSInteger unReadNum = [segmentBadgeValueFriend integerValue]+[[badgeDic valueForKey:@"z"] integerValue];
    BOOL i = unReadNum>0;
    [self.leveyTabBarController.tabBar setTabBarNoticeView:i withButtonIndex:1];
    
}

-(void)setSegmentBadgeValue:(NSString *)_value andMo:(NSString *)_moValue
{
    float width = [_value sizeWithFont:[UIFont boldSystemFontOfSize:14]].width+12;
    
    self.badgeViewFriend.badgeString = _value;
    self.badgeViewFriend.frame=CGRectMake(segmentController.frame.size.width / 2 -width+5, -2, width, 20);
    
    
    if(!_value.length||[_value isEqualToString:@"0"])
    {
        self.badgeViewFriend.hidden = YES;
    }
    else
    {
        self.badgeViewFriend.hidden = NO;
    }
    
    float moWidth = [_moValue sizeWithFont:[UIFont boldSystemFontOfSize:14]].width+12;
    
    self.badgeViewMo.badgeString = _moValue;
    self.badgeViewMo.frame=CGRectMake(segmentController.frame.size.width-moWidth+5, -2, moWidth, 20);
    
    
    if(!_moValue.length||[_moValue isEqualToString:@"0"])
    {
        self.badgeViewMo.hidden = YES;
    }
    else
    {
        self.badgeViewMo.hidden = NO;
    }
    
}
-(void)setTabBarBadgeValue:(NSString *)_value
{
    [self.leveyTabBarController.tabBar setBadgeValue:_value withButtonIndex:1];
}

- (void)viewDidLoad
{
    //zyfzyfzyf⬇️
    _dataArray=[[NSMutableArray alloc]init];
    //zyfzyfzyf⬆️
//    self.keywordString = @"";
    BanBu_ImageView *backImage = [[[BanBu_ImageView alloc]initWithBackGroundImageType:UIImageViewCreatTypeTable] autorelease];
    self.tableView.backgroundView = backImage;
    
    //监听删除
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deleteBroadcastAction:) name:@"delete_Broadcast" object:nil];
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.backgroundColor = [UIColor colorWithRed:255.0/255 green:250.0/255 blue:240.0/255 alpha:1.0];
    
    if(!_useridBroad.length)
    {
        [super viewDidLoad];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheme) name:kThemeDidChangeNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateBroadcastBadgeValue) name:@"setFriendActionNum" object:nil];
        alreadyRefresh = YES;
        isLoading      = NO;
        
//        imageDic = [[NSMutableDictionary alloc] init];
        [self setUpForDismissKeyboard];
        NSMutableDictionary *parDic = [NSMutableDictionary dictionary];
        [parDic setValue:[MyAppDataManager getLanguageSubmitToServer] forKey:@"lang"];
        
        BanBu_ImageView *backImage = [[[BanBu_ImageView alloc]initWithBackGroundImageType:UIImageViewCreatTypeTable] autorelease];
        self.tableView.backgroundView = backImage;
        
        
//        [AppComManager getBanBuData:BanBu_Get_Broad_Hotkey par:parDic delegate:self];
        
        _existDic = [[NSMutableDictionary alloc]initWithCapacity:1];
        
        cacheArray = [[NSMutableArray alloc] initWithCapacity:20];
        
        moreView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 80)];
        
        
        loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        //    loadingView.backgroundColor = [UIColor redColor];
        loadingView.hidden = NO;
        [loadingView setHidesWhenStopped:YES];
        loadingView.frame = CGRectMake(0, 0, 80, 80);
        loadingView.center = CGPointMake(160, 50);
        loadingView.center = CGPointMake(160-([NSLocalizedString(@"loadingNotice", nil) sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(320, 20) lineBreakMode:kTextLineBreakByWordWrapping].width/2)-15, 20);
        
        lab = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 320,20)];
        lab.font= [UIFont systemFontOfSize:15];
        //    lab.backgroundColor =[UIColor colorWithRed:254.0/255.0 green:250.0/255.0 blue:239.0/255.0 alpha:1];
        
        lab.backgroundColor = [UIColor clearColor];
        lab.text = NSLocalizedString(@"loadingNotice", nil);
        lab.textAlignment = kTextAlignmentCenter;
        lab.textColor = [UIColor grayColor];
        [moreView addSubview:lab];
        //    [moreView setBackgroundColor:[UIColor colorWithRed:254.0/255.0 green:250.0/255.0 blue:239.0/255.0 alpha:1]];
        [moreView setBackgroundColor:[UIColor clearColor]];
        [moreView addSubview:loadingView];
        [loadingView release];
        [self setLoadingMore:NO];
        segmentController = [[AKSegmentedControl alloc] initWithFrame:CGRectMake(5,5,196,34)];
        [segmentController setDelegate:self];
        [self setupSegmentedControl];
        BanBu_NavButton *rightButton = [[BanBu_NavButton alloc] initWithButtonType:UIButtonCreatTypeNormal];
        rightButton.position = ButtonPositionRight;
        rightButton.frame = CGRectMake(320-55, 27, 50, 30);
        rightButton.titleLabel.font = [UIFont systemFontOfSize:14];
//        [rightButton setTitle:NSLocalizedString(@"listButton", nil) forState:UIControlStateNormal];
        [rightButton setImage:[UIImage imageNamed:@"neardo_post.png"] forState:UIControlStateNormal];
        [rightButton addTarget:self action:@selector(releaseRadio) forControlEvents:UIControlEventTouchUpInside];
        listButton = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
        //    [rightButton setTitleEdgeInsets:UIEdgeInsetsMake(3, 2, 2, 2)];
        self.navigationItem.rightBarButtonItem = listButton;
        [rightButton release];
        
        BanBu_NavButton *leftButton=[[BanBu_NavButton alloc] initWithButtonType:UIButtonCreatTypeBack];
        leftButton.position = ButtonPositionLeft;
//        leftButton.frame=CGRectMake(5, 27, 40, 30);
        //    [leftButton setTitleEdgeInsets:UIEdgeInsetsMake(3, 9, 2, 2)];
//        [leftButton setTitle:NSLocalizedString(@"returnButton", nil) forState:UIControlStateNormal];
//        leftButton.titleLabel.font = [UIFont systemFontOfSize:14];
        
        [leftButton addTarget:self action:@selector(misPop) forControlEvents:UIControlEventTouchUpInside];
        btn_return = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
        
        searchView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320,50)];

        search=[[UITextField alloc]initWithFrame:CGRectMake(20, 15, 160, 30)];
        search.placeholder = NSLocalizedString(@"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      ", nil);
        search.delegate = self;
        search.textColor = [UIColor redColor];
        search.layer.borderColor = [[UIColor lightGrayColor] CGColor];
        search.layer.borderWidth = 1.0;
        search.layer.cornerRadius = 4;
        search.clearButtonMode = UITextFieldViewModeWhileEditing;
        search.returnKeyType = UIReturnKeySearch;
        [search setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
        search.backgroundColor = [UIColor clearColor];
        [searchView addSubview:search];
        UILabel *paddingView = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 5, 30)];
        paddingView.backgroundColor = [UIColor clearColor];
        search.leftView = paddingView;
        search.leftViewMode = UITextFieldViewModeAlways;
        [paddingView release];
        BanBu_NavButton *aSearchButton = [[BanBu_NavButton alloc] initWithButtonType:UIButtonCreatTypeCustomBtn];
        [aSearchButton addTarget:self action:@selector(goSearchBroad:) forControlEvents:UIControlEventTouchUpInside];
        [aSearchButton setTitle:NSLocalizedString(@"searchBroadcast", nil) forState:UIControlStateNormal];

        aSearchButton.frame=CGRectMake(200, 15, 103, 30);

        //    [aSearchButton setTitleEdgeInsets:UIEdgeInsetsMake(3, 2, 2, 2)];
        aSearchButton.titleLabel.font = [UIFont boldSystemFontOfSize:18];
        [searchView addSubview:aSearchButton];
        //隐藏搜索
        /*
         self.tableView.tableHeaderView = searchView;
        */
        
         
        NSString *broadcastPath = [DataCachePath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@-broadcastdata",MyAppDataManager.useruid]];
        [MyAppDataManager.nearDos addObjectsFromArray:[NSKeyedUnarchiver unarchiveObjectWithData:[NSData dataWithContentsOfFile:broadcastPath]]];

        //监听从动态详情页面，点击标签事件
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(fromDetialGoSearchBroad:) name:@"xiangqingAction" object:nil];
        //监听是否是第二次点击tabbar
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(refreshBroadcast) name:@"refreshBroadcast" object:nil];
        farDemeter = @"100000";
        
        
        _badgeViewFriend = [[UIBadgeView alloc] init];
        
        self.badgeViewFriend.backgroundColor = [UIColor clearColor];
        self.badgeViewFriend.badgeColor = [UIColor redColor];
        [segmentController addSubview:_badgeViewFriend];
        
        _badgeViewMo = [[UIBadgeView alloc] init];
        
        self.badgeViewMo.backgroundColor = [UIColor clearColor];
        self.badgeViewMo.badgeColor = [UIColor redColor];
        [segmentController addSubview:_badgeViewMo];
        
        [self updateBroadcastBadgeValue];
        
    }
    else
    {
//        moreView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
//        moreView.backgroundColor = [UIColor clearColor];
//        self.tableView.tableFooterView = moreView;
        
        cacheArray = [[NSMutableArray alloc] initWithCapacity:20];
        
        moreView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
        
        
        loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        //    loadingView.backgroundColor = [UIColor redColor];
        loadingView.hidden = NO;
        [loadingView setHidesWhenStopped:YES];
        loadingView.frame = CGRectMake(0, 0, 80, 80);
        loadingView.center = CGPointMake(160, 50);
        loadingView.center = CGPointMake(160-([NSLocalizedString(@"loadingNotice", nil) sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(320, 20) lineBreakMode:kTextLineBreakByWordWrapping].width/2)-15, 20);
        
        lab = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 320,20)];
        lab.font= [UIFont systemFontOfSize:15];
        //    lab.backgroundColor =[UIColor colorWithRed:254.0/255.0 green:250.0/255.0 blue:239.0/255.0 alpha:1];
        
        lab.backgroundColor = [UIColor clearColor];
        lab.text = NSLocalizedString(@"loadingNotice", nil);
        lab.textAlignment = kTextAlignmentCenter;
        lab.textColor = [UIColor grayColor];
        [moreView addSubview:lab];
        //    [moreView setBackgroundColor:[UIColor colorWithRed:254.0/255.0 green:250.0/255.0 blue:239.0/255.0 alpha:1]];
        [moreView setBackgroundColor:[UIColor clearColor]];
        [moreView addSubview:loadingView];
        [loadingView release];
        [self setLoadingMore:NO];

        [self loadingData];
        
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        //    self.tableView.backgroundView = nil;
        self.tableView.backgroundColor = [UIColor colorWithRed:255.0/255 green:250.0/255 blue:240.0/255 alpha:1.0];
    }
    
}


//点击关键字搜索
-(void)placeSelect:(UIButton *)sender
{
    [search resignFirstResponder];
    search.text = sender.titleLabel.text;
    search.textColor = sender.titleLabel.textColor;
    [self goSearchBroad:sender];
}

-(void)refreshBroadcast
{
    [self setRefreshing];
}

-(void)deleteBroadcastAction:(NSNotification *)aNoti
{
    NSMutableDictionary *parDic = [NSMutableDictionary dictionary];
    [parDic setValue:[aNoti object] forKey:@"actid"];
    [AppComManager getBanBuData:BanBu_Delete_Broadcast par:parDic delegate:self];
    self.view.userInteractionEnabled = NO;
    
}

-(void)releaseRadio
{
    BanBu_PictureAndVoice *aPicAndVoice = [[BanBu_PictureAndVoice alloc]init];
    [self.leveyTabBarController hidesTabBar:YES animated:YES];
    
    [self.navigationController pushViewController:aPicAndVoice animated:YES];
    [aPicAndVoice release];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    if(!_useridBroad.length)
    {
        self.tableView.tableFooterView = moreView;
        if((!MyAppDataManager.nearDos.count ||!_DosPage)&&!_useridBroad.length){
            [self setRefreshing];
            return;
        }
        //判断是否要刷新页面
        NSString *timeNowString = [BanBu_RefreshTime getCurrentTime:nil];
        BOOL isReload = [BanBu_RefreshTime now:timeNowString isLaterBefore:[UserDefaults valueForKey:@"squares_updateTime"]];
        if(isReload){
            [segmentController setSelectedIndex:0];
//            [self setRefreshing];
        }
    }
    else
    {
        NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:[MyAppDataManager getUserBaseDataWithKey:KeyLastSeeDynamicTime]];
        
        NSString *timeString = [MyAppDataManager getServerTime];
        [dic setValue:timeString forKey:_useridBroad];
        
        [MyAppDataManager modifyUserBaseDataWithKey:KeyLastSeeDynamicTime andData:dic];
        
    }
}

-(void)viewWillDisappear:(BOOL)animated{
    
    //    [self.tableView reloadRowsAtIndexPaths:[self.tableView indexPathsForVisibleRows]withRowAnimation:UITableViewRowAnimationNone];
    if(!_useridBroad.length)
    {
        [super viewWillDisappear:animated];
        [UIView animateWithDuration:0.5 animations:^{
            self.navigationItem.leftBarButtonItem = nil;
            self.navigationItem.leftBarButtonItem = nil;
        }];
    }
}

-(void)viewWillAppear:(BOOL)animated
{
    [UIView setAnimationsEnabled:YES];
    [super viewWillAppear:animated];
    if(!_useridBroad.length)
    {
        [self.leveyTabBarController hidesTabBar:NO animated:YES];
            [UIView animateWithDuration:0.5 animations:^{
            if(isFirst){
                self.navigationItem.leftBarButtonItem = btn_return;
                self.navigationItem.rightBarButtonItem = nil;
            }else{
                self.navigationItem.leftBarButtonItem = nil;
                self.navigationItem.rightBarButtonItem = listButton;
            }
        }];
    }
    else
    {
        //        BanBu_NavButton *leftButton=[[BanBu_NavButton alloc] initWithButtonType:UIButtonCreatTypeBack];
        //        leftButton.position = ButtonPositionLeft;
        //        leftButton.frame=CGRectMake(5, 27, 48, 30);
        //        //    [leftButton setTitleEdgeInsets:UIEdgeInsetsMake(3, 9, 2, 2)];
        //        [leftButton setTitle:NSLocalizedString(@"returnButton", nil) forState:UIControlStateNormal];
        //        leftButton.titleLabel.font = [UIFont systemFontOfSize:14];
        //        [leftButton addTarget:self action:@selector(popself) forControlEvents:UIControlEventTouchUpInside];
        //        UIBarButtonItem *returnBtn = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
        //        self.navigationItem.leftBarButtonItem = returnBtn;
    }
}
-(void)popself
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)fromDetialGoSearchBroad:(NSNotification *)notifi{
    isFirst = YES;
    UIButton *aButton = (UIButton *)[notifi object];
    self.keywordString = [aButton.titleLabel.text substringFromIndex:1];
    self.navigationItem.title = [NSString stringWithFormat:@"#%@",self.keywordString];
    [self setRefreshing];
        [UIView animateWithDuration:0.5 animations:^{
        //        btn_return.alpha = 1;
        //        listButton.alpha = 0;
        self.navigationItem.leftBarButtonItem = btn_return;
        self.navigationItem.rightBarButtonItem = nil;
        
    }];
    
}

//看标签的广播
-(void)goSearchBroad:(UIButton *)sender{
    //    [AppComManager cancalHandlesForObject:self];
    if(!_useridBroad.length)
    {
        [search resignFirstResponder];
        if(!_isLoadingRefresh)
        {
            if([sender.titleLabel.text hasPrefix:@"#"])
            {
                self.keywordString = [sender.titleLabel.text substringFromIndex:1];
            }
            else
            {
                if([search.text hasPrefix:@"#"])
                {
                    self.keywordString = [search.text substringFromIndex:1];
                }
                else
                    self.keywordString = search.text;
            }
            [segmentController removeFromSuperview];
            self.navigationItem.titleView = nil;
            self.navigationItem.title = [NSString stringWithFormat:@"#%@",NSLocalizedString(self.keywordString, nil)];
            [self setRefreshing];
                [UIView animateWithDuration:0.5 animations:^{
                //        btn_return.alpha = 1;
                //        listButton.alpha = 0;
                self.navigationItem.leftBarButtonItem = btn_return;
                self.navigationItem.rightBarButtonItem = nil;
            }];
            isFirst = YES;
        }
    }
    
}

-(void)misPop{
    self.keywordString = @"";
    self.navigationItem.title = @"";
    self.navigationItem.titleView = segmentController;
    [self setRefreshing];
    
        [UIView animateWithDuration:0.5 animations:^{
        //        btn_return.alpha = 0;
        //        listButton.alpha = 1;
        self.navigationItem.leftBarButtonItem = nil;
        self.navigationItem.rightBarButtonItem = listButton;
        
    }];
    isFirst = NO;
}



#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    // Return the number of sections.
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(_useridBroad.length)
        return MyAppDataManager.friendDos.count;
    return MyAppDataManager.nearDos.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //zyfzyfzyf⬇️判断cell
    NSDictionary * cellDic=[NSDictionary dictionary];
    if(_useridBroad.length)
    {
        if(MyAppDataManager.friendDos.count)
        {
            
            cellDic= [MyAppDataManager.friendDos objectAtIndex:indexPath.row];
        }
        else
        {
            cellDic = nil;
        }
    }
    
    else
    {
        if(MyAppDataManager.nearDos.count){
            
            cellDic = [MyAppDataManager.nearDos objectAtIndex:indexPath.row];
        }else{
            cellDic = nil;
        }
    }
    BanBu_DigiCell * cell = nil;
    BanBu_magicWordsCell * Magiccell;
    
    NSDictionary * kindDic=[[cellDic valueForKey:@"actioninfor"] valueForKey:@"mcontent"] ;
    //实验
    //  NSUserDefaults * defau=[NSUserDefaults standardUserDefaults];
    //  NSDictionary * kindDic=[defau objectForKey:@"send"] ;
    //
    if ([[kindDic valueForKey:@"mkind"] isEqualToString:@"html"]) {
        //魔法文字Cell
        static NSString *CellIdHtml = @"HtmlCell";
        
        Magiccell=[tableView dequeueReusableCellWithIdentifier:CellIdHtml];
        if (Magiccell==nil) {
            Magiccell=[[BanBu_magicWordsCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdHtml];
            
        }
        [Magiccell setWebviewWithDic:kindDic];
        cell.sayTextLabel.hidden=YES;
        cell.headImageView.hidden=YES;
        cell.sayTextLabel=nil;
        
        cell=Magiccell;
    }
    else
    {
        //普通cell
        static NSString *CellIdentifier = @"Cell";
        BanBu_DigiCell *cell2 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if(!cell2){
            cell2 = [[[BanBu_DigiCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
            cell2.backgroundColor = [UIColor clearColor];
            UIView *aView = [[UIView alloc]init];
            aView.backgroundColor = [UIColor clearColor];
            cell2.selectedBackgroundView = aView;
            [aView release];
        }
        cell=cell2;
    }
    //zyfzyfzyf⬆️
    cell.delegate = self;
    NSDictionary *nearDic;
    NSDictionary *conDic;
    
    if(_useridBroad.length)
    {
        if(MyAppDataManager.friendDos.count-1<indexPath.row)
        {
            return cell;
        }
        if(MyAppDataManager.friendDos.count)
        {

            nearDic= [MyAppDataManager.friendDos objectAtIndex:indexPath.row];
        }
        else
        {
         //   nearDic = nil;
            //zyfzyfzyf⬇️如果MyAppDataManager.friendDos为空，采用本地数据
            nearDic =[_dataArray objectAtIndex:indexPath.row];
            [MyAppDataManager.friendDos setArray:_dataArray];
            //zyfzyfzyf⬆️

        }
    }
    
    else
    {
        if(MyAppDataManager.nearDos.count-1<indexPath.row)
        {
            return cell;
        }
        if(MyAppDataManager.nearDos.count){

            nearDic= [MyAppDataManager.nearDos objectAtIndex:indexPath.row];
        }else{
          //  nearDic= nil;
            //zyfzyfzyf⬇️如果MyAppDataManager.nearDos为空，采用本地数据
            nearDic =[_dataArray objectAtIndex:indexPath.row];
            [MyAppDataManager.nearDos setArray:_dataArray];
            //zyfzyfzyf⬆️

        }
    }
    
    
    NSDictionary *nearDo = [nearDic valueForKey:@"actioninfor"];
    conDic = [nearDo valueForKey:@"mcontent"];
    NSDictionary *userInfor = [nearDic valueForKey:@"userinfor"];
    
    cell.nameLabel.text = [userInfor objectForKey:@"pname"];
    if(![[nearDo objectForKey:@"adtime"] isEqualToString:@""] && ![[nearDo objectForKey:@"admeter"] isEqualToString:@""]){
        [cell setDistance:[nearDo objectForKey:@"admeter"] aDtime:[nearDo objectForKey:@"adtime"]];
    }
    
    [cell setAge:[userInfor objectForKey:@"oldyears"] sex:[userInfor objectForKey:@"gender"] verify:[[userInfor objectForKey:@"verify"] boolValue]];
    [cell setVIPFlag:[[userInfor valueForKey:@"userlevel"] integerValue]>0];
    cell.lastTimeLabel.text = [MyAppDataManager getTheLastOnlineTime:[nearDo objectForKey:@"mtime"]];
    //    cell.headImageView.image = [imageDic valueForKey:_imageContentString];
    
    [cell setAvatar:[userInfor objectForKey:@"uface"]];
    //按钮上的文字，来作为标示。 播放的语音也是一样的。
    [cell.iconButton setTitle:[NSString stringWithFormat:@"%d",indexPath.row] forState:UIControlStateNormal];
    [cell.iconButton setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
    /****************排版**********************/
    
    //文字
    
    BOOL _isText =![[conDic valueForKey:@"saytext"]isEqualToString:@""];
    if(_isText){
        //只有文字，没有标签
        if(cell.tagsView.subviews.count){
            for(UIButton *temp in cell.tagsView.subviews){
                [temp removeFromSuperview];
            }
            cell.tagsView.frame = CGRectZero;
        }
        NSString *saytext = [conDic objectForKey:@"saytext"];
        
        if([saytext rangeOfString:@"-->"].location != NSNotFound && [saytext rangeOfString:@"<--"].location != NSNotFound){
            
            NSInteger start=[saytext rangeOfString:@"<--"].location+3;
            NSInteger end = [saytext rangeOfString:@"-->"].location;
            cell.sayTextLabel.text = [saytext substringToIndex:start-3];
            _textHeight = [cell.sayTextLabel.text sizeWithFont:[UIFont systemFontOfSize:13] constrainedToSize:CGSizeMake(235, 100) lineBreakMode:kTextLineBreakByTruncatingMiddle].height;
            cell.sayTextLabel.frame = CGRectMake(55, 55, 235, _textHeight);
            
            NSString *tagString = [saytext substringWithRange:NSMakeRange(start, end-start)];
            
            if(![tagString isEqualToString:@""])
            {
                if(cell.sayTextLabel.text.length){
                    _textHeight += 5;
                }
                NSArray *tagArray = [tagString componentsSeparatedByString:@" "];
                CGFloat height= 0,width = 0;
                for(int i= 0;i<tagArray.count;i++){
                    NSString *buttonTitle = [NSString stringWithFormat:@"#%@",[tagArray objectAtIndex:i]];
                    UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
                    aButton.backgroundColor = [UIColor clearColor];
                    [aButton setTitle:buttonTitle forState:UIControlStateNormal];
                    aButton.titleLabel.font = [UIFont systemFontOfSize:13];
                    [aButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
                    CGFloat buttonLength = [buttonTitle sizeWithFont:[UIFont systemFontOfSize:13]].width;
                    if(width > 235-buttonLength){
                        width = 0;
                        height += 15;
                    }
                    aButton.frame = CGRectMake(width, height, buttonLength, 17);
                    width += buttonLength+5;
                    [aButton addTarget:self action:@selector(goSearchBroad:) forControlEvents:UIControlEventTouchUpInside];
                    [cell.tagsView addSubview:aButton];
                    
                }
                cell.tagsView.frame = CGRectMake(55, 55+_textHeight, 235, height+17);
                _textHeight += height + 17;
            }
        }
        else{
            
            
            //2014年10月27日17:27:38 by 张毅飞⬇️根据cell类型设置坐标
            if ([[kindDic valueForKey:@"mkind"] isEqualToString:@"html"]) {
                //   _textHeight=[Magiccell getWebviewHeight];
                //   _textHeight=30;
                cell.sayTextLabel.text = [conDic objectForKey:@"saytext"];
                _textHeight = [cell.sayTextLabel.text sizeWithFont:[UIFont systemFontOfSize:13] constrainedToSize:CGSizeMake(235, 60) lineBreakMode:kTextLineBreakByTruncatingMiddle].height+5;
            }
            else
            {
                cell.sayTextLabel.text = [conDic objectForKey:@"saytext"];
                _textHeight = [cell.sayTextLabel.text sizeWithFont:[UIFont systemFontOfSize:13] constrainedToSize:CGSizeMake(235, 100) lineBreakMode:kTextLineBreakByTruncatingMiddle].height+5;
                
            }
            cell.sayTextLabel.frame = CGRectMake(55, 55, 235, _textHeight);
            //2014年10月27日17:27:56 by 张毅飞 根据cell类型设置坐标⬆️
            
        }
        _textHeight += 5;
    }
    else{
        cell.sayTextLabel.frame = CGRectZero;
        _textHeight = 0;
        if(cell.tagsView.subviews.count)
        {
            for(UIButton *temp in cell.tagsView.subviews)
            {
                [temp removeFromSuperview];
            }
            cell.tagsView.frame = CGRectZero;
            
        }
    }
    
    if([[nearDo objectForKey:@"telno"] length])
    {
        cell.telButton.frame = CGRectMake(75, 55+_textHeight+10, 210, 30);
        //                [cell.telButton setBackgroundColor:[UIColor redColor]];
        [cell.telButton.titleLabel setFont:[UIFont systemFontOfSize:17]];
        [cell.telButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        //                [cell.telButton.titleLabel setTextColor:[UIColor blackColor]];
        cell.telLabel.frame = CGRectMake(55,55+_textHeight+10,50,30);
        [cell.telButton setTitle:[nearDo objectForKey:@"telno"] forState:UIControlStateNormal];
        _textHeight += 30;
        
    }
    else
    {
        cell.telButton.frame = CGRectZero;
        cell.telLabel.frame = CGRectZero;
        
    }
    
    if([[nearDo objectForKey:@"tourl"] length])
    {
        CGFloat w = [[nearDo valueForKey:@"tourl"] sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(__MainScreen_Width-80, 30) lineBreakMode:kTextLineBreakByWordWrapping].width;
        cell.netAdress.frame = CGRectMake(105, 55+_textHeight+10, w, 30);
        [cell.netAdress.titleLabel setFont:[UIFont systemFontOfSize:17]];
        [cell.netAdress setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        cell.netLabel.frame = CGRectMake(55,55+_textHeight+10,50,30);
        [cell.netAdress setTitle:[nearDo objectForKey:@"tourl"] forState:UIControlStateNormal];
        _textHeight += 30;
        
    }
    else
    {
        cell.netLabel.frame = CGRectZero;
        cell.netAdress.frame = CGRectZero;
    }
    
    
    //图片和语音
    _imageContentString = nil;
    _soundContentString = nil;
    _soundTimeString = nil;
    
    
    for(NSDictionary *aDic in [conDic valueForKey:@"attach"]){
        if([[aDic valueForKey:@"type"] isEqualToString:@"image"]){
            if(![[aDic valueForKey:@"content"]isEqualToString:@""]){
                _imageContentString = [NSString stringWithString:[aDic valueForKey:@"content"]];
            }
        }else if([[aDic valueForKey:@"type"] isEqualToString:@"sound"]){
            if(![[aDic valueForKey:@"content"]isEqualToString:@""]){
                
                _soundContentString = [NSString stringWithFormat:@"0,%@",[aDic valueForKey:@"content"]];
                if([aDic valueForKey:@"length"]){
                    _soundTimeString = [NSString stringWithFormat:@"%@\"",[aDic valueForKey:@"length"]];
                    
                }
                
            }
        }
    }
    if(_imageContentString){
        [cell setHeadImage:_imageContentString];
        cell.headImageView.frame = CGRectMake(10, 55+_textHeight, 280,280);
        _headImageViewHeight = cell.headImageView.frame.size.height+10;
        
        if(_soundContentString){
            cell.playButton.hidden = NO;
            [cell.playButton setTitle:_soundContentString forState:UIControlStateNormal];
            [cell.playButton setImage:[UIImage imageNamed:@"播放语音_未按下_不空.png"] forState:UIControlStateNormal];
            [cell.playButton setFrame:CGRectMake(0, 0, 105, 26)];
            if(displayCell==indexPath.row)
            {
                _voiceButton = cell.playButton;
                [self animation:_voiceButton];
            }
            cell.playButton.tag = 999+indexPath.row;
            cell.playButton.center = CGPointMake(__MainScreen_Width/2, _headImageViewHeight+55+_textHeight-13);
            
            cell.soundTimeLabel.text = _soundTimeString;
            _headImageViewHeight = cell.headImageView.frame.size.height+23;
            [cell.soundTimeLabel setFrame:CGRectMake(0, 0, 105, 26)];
            cell.soundTimeLabel.frame = CGRectMake(cell.playButton.frame.origin.x+60-10-25+45, cell.playButton.frame.origin.y+3, 25, 20);
            
            
        }else{
            cell.playButton.frame = CGRectZero;
            cell.playButton.hidden = YES;
            cell.soundTimeLabel.frame = CGRectZero;
        }
    }
    else{
        cell.headImageView.frame = CGRectZero;
        cell.playButton.hidden = YES;
        cell.playButton.frame = CGRectZero;
        cell.soundTimeLabel.frame = CGRectZero;
        _headImageViewHeight = 0;
    }
    
    
    
    //        NSDictionary *userInfor = [nearDic valueForKey:@"userinfor"];
    //评论
    BOOL _isReplylist =  [[nearDic valueForKey:@"replylist"] count]?YES:NO;
    if(_isReplylist){
        NSArray *replyList = [NSArray arrayWithArray:[nearDic valueForKey:@"replylist"]];
        {
            cell.lineView1.frame = CGRectZero;
            cell.iconBtn1.frame = CGRectZero;
            cell.voiceBtn1.frame = CGRectZero;
            cell.nameLabel1.frame = CGRectZero;
            cell.replyNameLabel1.frame = CGRectZero;
            cell.textLabel1.frame = CGRectZero;
            cell.timeLabel1.frame =CGRectZero;
            
            cell.lineView2.frame = CGRectZero;
            cell.iconBtn2.frame = CGRectZero;
            cell.voiceBtn2.frame = CGRectZero;
            cell.nameLabel2.frame = CGRectZero;
            cell.replyNameLabel2.frame = CGRectZero;
            cell.textLabel2.frame = CGRectZero;
            cell.timeLabel2.frame =CGRectZero;
            
            cell.lineView3.frame = CGRectZero;
            cell.iconBtn3.frame = CGRectZero;
            cell.voiceBtn3.frame = CGRectZero;
            cell.nameLabel3.frame = CGRectZero;
            cell.replyNameLabel3.frame = CGRectZero;
            cell.textLabel3.frame = CGRectZero;
            cell.timeLabel3.frame =CGRectZero;
            
            cell.soundTimeLabel1.frame = CGRectZero;
            cell.soundTimeLabel2.frame = CGRectZero;
            cell.soundTimeLabel3.frame = CGRectZero;
            
        }
        for(int i=0; i<[replyList count]; i++)
        {
            
            NSDictionary *replyContent = [AppComManager getAMsgFrom64String:[[replyList objectAtIndex:i] valueForKey:@"mcontent"]];
            if(i==0){
                //评论1
                
                [cell.iconBtn1 setTitle:[NSString stringWithFormat:@"%d-%d",indexPath.row,i]  forState:UIControlStateNormal];
                [cell.iconBtn1 setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
                [cell.iconBtn1 setImageWithURL:[NSURL URLWithString:[[replyList objectAtIndex:0] valueForKey:@"uface"]] placeholderImage:[UIImage imageNamed:@"default.png"] andType:1];
                cell.nameLabel1.text = [[replyList objectAtIndex:0] valueForKey:@"pname"];
                if([[replyContent valueForKey:@"saytext"]isEqualToString:@""]){
                    cell.replyCellHeight = 0;
                     cell.lineView1.frame = CGRectMake(0,0, 300, 1);
                    cell.iconBtn1.frame = CGRectMake(10, 10+cell.replyCellHeight, 35, 35);
                    CGFloat nameWidth = [cell.nameLabel1.text sizeWithFont:cell.nameLabel1.font constrainedToSize:CGSizeMake(80, 17) lineBreakMode:kTextLineBreakByTruncatingTail].width;
                    cell.nameLabel1.frame = CGRectMake(55, 19, nameWidth, 17);
                    //语音按钮
                    [cell.voiceBtn1 setImage:[UIImage imageNamed:@"广播详情-复选框-播放.png"] forState:UIControlStateNormal];
                    [cell.voiceBtn1 setTitle:[NSString stringWithFormat:@"1,%@",[[[replyContent valueForKey:@"attach"] objectAtIndex:0] valueForKey:@"content"]] forState:UIControlStateNormal];
                    cell.voiceBtn1.frame = CGRectMake(cell.nameLabel1.frame.origin.x+nameWidth+10, 15, 60, 25);
                    if([[[replyContent valueForKey:@"attach"] objectAtIndex:0] valueForKey:@"length"]){
                        cell.soundTimeLabel1.text = [NSString stringWithFormat:@"%@\"",[[[replyContent valueForKey:@"attach"] objectAtIndex:0] valueForKey:@"length"]];
                        
                    }
                    
                    cell.soundTimeLabel1.frame = CGRectMake(cell.voiceBtn1.frame.origin.x+60-10-25, cell.voiceBtn1.frame.origin.y+2, 25, 20);
                    cell.replyCellHeight += 55;
                    
                }else{

                    [cell setReplySayText1:replyContent];
//                    cell.textLabel1.text = [replyContent valueForKey:@"saytext"];
                    
                }
                cell.timeLabel1.frame =CGRectMake(215, cell.nameLabel1.frame.origin.y, 75, 17);
                
                cell.timeLabel1.text = [MyAppDataManager getTheLastOnlineTime:[[replyList objectAtIndex:0] valueForKey:@"mtime"]];
                
            }
            else if(i==1){
               

                [cell.iconBtn2 setTitle:[NSString stringWithFormat:@"%d-%d",indexPath.row,i]  forState:UIControlStateNormal];
                [cell.iconBtn2 setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
                [cell.iconBtn2 setImageWithURL:[NSURL URLWithString:[[replyList objectAtIndex:1] valueForKey:@"uface"]] placeholderImage:[UIImage imageNamed:@"default.png"] andType:1];
                cell.nameLabel2.text = [[replyList objectAtIndex:1] valueForKey:@"pname"];
                if([[replyContent valueForKey:@"saytext"]isEqualToString:@""]){
                   cell.iconBtn2.frame = CGRectMake(10, 10+cell.replyCellHeight, 35, 35);
                    cell.lineView2.frame = CGRectMake(0,cell.replyCellHeight, 300, 1);
                    CGFloat nameWidth = [cell.nameLabel2.text sizeWithFont:cell.nameLabel2.font constrainedToSize:CGSizeMake(80, 17) lineBreakMode:kTextLineBreakByTruncatingTail].width;
                    cell.nameLabel2.frame = CGRectMake(55, 19+55, nameWidth, 17);
                    
                    //语音按钮
                    [cell.voiceBtn2 setImage:[UIImage imageNamed:@"广播详情-复选框-播放.png"] forState:UIControlStateNormal];
                    [cell.voiceBtn2 setTitle:[NSString stringWithFormat:@"1,%@",[[[replyContent valueForKey:@"attach"] objectAtIndex:0] valueForKey:@"content"]] forState:UIControlStateNormal];
                    
                    cell.voiceBtn2.frame = CGRectMake(cell.nameLabel2.frame.origin.x+nameWidth+10, 15+55, 60, 25);
                    
                    if([[[replyContent valueForKey:@"attach"] objectAtIndex:0] valueForKey:@"length"]){
                        cell.soundTimeLabel2.text = [NSString stringWithFormat:@"%@\"",[[[replyContent valueForKey:@"attach"] objectAtIndex:0] valueForKey:@"length"]];
                        
                    }
                    cell.soundTimeLabel2.frame = CGRectMake(cell.voiceBtn2.frame.origin.x+60-10-25, cell.voiceBtn2.frame.origin.y+2, 25, 20);
                    cell.replyCellHeight += 55;
                    
                }
                else{

                    [cell setReplySayText2:replyContent];
//                    cell.textLabel2.text = [replyContent valueForKey:@"saytext"];
                }
                cell.timeLabel2.frame =CGRectMake(215, cell.nameLabel2.frame.origin.y, 75, 17);
                cell.timeLabel2.text = [MyAppDataManager getTheLastOnlineTime:[[replyList objectAtIndex:1] valueForKey:@"mtime"]];
            }
            else if(i == 2){
                [cell.iconBtn3 setTitle:[NSString stringWithFormat:@"%d-%d",indexPath.row,i]  forState:UIControlStateNormal];
                [cell.iconBtn3 setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
                [cell.iconBtn3 setImageWithURL:[NSURL URLWithString:[[replyList objectAtIndex:2] valueForKey:@"uface"]] placeholderImage:[UIImage imageNamed:@"default.png"] andType:1];
                cell.nameLabel3.text = [[replyList objectAtIndex:2] valueForKey:@"pname"];
                if([[replyContent valueForKey:@"saytext"]isEqualToString:@""]){
                   cell.lineView3.frame = CGRectMake(0,cell.replyCellHeight, 300, 1);
                    cell.iconBtn3.frame = CGRectMake(10, 10+cell.replyCellHeight, 35, 35);
                    CGFloat nameWidth = [cell.nameLabel3.text sizeWithFont:cell.nameLabel3.font constrainedToSize:CGSizeMake(80, 17) lineBreakMode:kTextLineBreakByTruncatingTail].width;
                    cell.nameLabel3.frame = CGRectMake(55, 19+55*2, nameWidth, 17);
                    //语音按钮
                    [cell.voiceBtn3 setImage:[UIImage imageNamed:@"广播详情-复选框-播放.png"] forState:UIControlStateNormal];
                    [cell.voiceBtn3 setTitle:[NSString stringWithFormat:@"1,%@",[[[replyContent valueForKey:@"attach"] objectAtIndex:0] valueForKey:@"content"]] forState:UIControlStateNormal];
                    
                    cell.voiceBtn3.frame = CGRectMake(cell.nameLabel3.frame.origin.x+nameWidth+10, 15+110, 60, 25);
                    if([[[replyContent valueForKey:@"attach"] objectAtIndex:0] valueForKey:@"length"]){
                        cell.soundTimeLabel3.text = [NSString stringWithFormat:@"%@\"",[[[replyContent valueForKey:@"attach"] objectAtIndex:0] valueForKey:@"length"]];
                        
                    }
                    cell.soundTimeLabel3.frame = CGRectMake(cell.voiceBtn3.frame.origin.x+60-10-25, cell.voiceBtn3.frame.origin.y+2, 25, 20);
                     cell.replyCellHeight += 55;
                }else{
                  
                    [cell setReplySayText3:replyContent];
//                    cell.textLabel3.text = [replyContent valueForKey:@"saytext"];
                }
                
                cell.timeLabel3.frame =CGRectMake(215, cell.nameLabel3.frame.origin.y, 75, 17);
                cell.timeLabel3.text = [MyAppDataManager getTheLastOnlineTime:[[replyList objectAtIndex:2] valueForKey:@"mtime"]];
            }
        }
        
        cell.commentView.frame = CGRectMake(10, 55+_textHeight+_headImageViewHeight+10, 300, 30+cell.replyCellHeight);
//        cell.numLabel.frame = CGRectMake(10, cell.replyCellHeight+6.5, 180, 17);
//        cell.numLabel.text = [NSString stringWithFormat:@"%@ %@ %@",NSLocalizedString(@"commentcount1", nil),[nearDo valueForKey:@"comments"],NSLocalizedString(@"commentcount2", nil)];
        
        NSLog(@"%@",nearDo);
        cell.commentBtn.frame = CGRectMake(10, cell.replyCellHeight+6.5, 60, 20);
        [cell.commentBtn setTitle:[nearDo valueForKey:@"comments"] forState:UIControlStateNormal];
        
        cell.zanBtn.frame = CGRectMake(80, cell.replyCellHeight+6.5, 60, 20);
        [cell.zanBtn setTitle:[nearDo valueForKey:@"vote"] forState:UIControlStateNormal];
        
        cell.lineView4.frame = CGRectMake(0, cell.commentView.frame.size.height-30, 300, 1.0);
    }
    else{
        for(UIView *aTemp in cell.commentView.subviews){
            aTemp.frame = CGRectZero;
        }
        NSLog(@"%@",nearDo);
        cell.commentView.frame = CGRectMake(10, 55+_textHeight+_headImageViewHeight+10, 300, 30);
//        cell.commentView.backgroundColor = [UIColor blueColor];
//        cell.numLabel.frame = CGRectMake(10, 6.5, 180, 17);
//        cell.numLabel.text = NSLocalizedString(@"footLabel", nil);
        cell.commentBtn.frame = CGRectMake(10, 6.5, 60, 20);
        [cell.commentBtn setTitle:@"0" forState:UIControlStateNormal];
        
        cell.zanBtn.frame = CGRectMake(80,6.5, 60, 20);
        [cell.zanBtn setTitle:[nearDo valueForKey:@"vote"] forState:UIControlStateNormal];
        cell.lineView4.frame = CGRectMake(0, cell.commentView.frame.size.height-30, 300, 1.0);
    }
    
    cell.shadowView.frame = CGRectMake(10, 10, 300, 55+_textHeight+_headImageViewHeight+cell.commentView.frame.size.height);
    
    CGRect arect = cell.frame;
    arect.size.height = cell.shadowView.frame.size.height+10;
    cell.frame = arect ;
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [self getHeightOfCell:indexPath]+10;
}
-(CGFloat)getHeightOfCell:(NSIndexPath *)indexPath
{
    NSDictionary *nearDic;
    if(_useridBroad.length)
    {
        if(MyAppDataManager.friendDos.count)
        {
            nearDic= [MyAppDataManager.friendDos objectAtIndex:indexPath.row];
        }
        else
        {
            nearDic = nil;
        }
    }
    
    else
    {
        if(MyAppDataManager.nearDos.count){
            nearDic= [MyAppDataManager.nearDos objectAtIndex:indexPath.row];
        }else{
            nearDic= nil;
        }
    }

    NSDictionary *nearDo = [nearDic valueForKey:@"actioninfor"];
    
    NSDictionary *conDic = [nearDo valueForKey:@"mcontent"];
    
    
    //    [nearDo setValue:@"+8615711471686" forKey:@"telno"];
    //    [nearDo setValue:@"http://www.baidu.com" forKey:@"tourl"];
    
    //    NSDictionary *userinfor = [nearDic valueForKey:@"userinfor"];
    float height = 0;
    //    NSString *avar = [userinfor valueForKey:KeyUface];
    //    if(avar.length)
    //    {
    height += 55;
    //    }
    NSString *sayString;
    
    NSString *saytext = [conDic valueForKey:@"saytext"];
    
    if(![[conDic valueForKey:@"saytext"]isEqualToString:@""])
    {
        if([saytext rangeOfString:@"-->"].location != NSNotFound && [saytext rangeOfString:@"<--"].location != NSNotFound){
            
            NSInteger start=[saytext rangeOfString:@"<--"].location+3;
            NSInteger end = [saytext rangeOfString:@"-->"].location;
            sayString = [saytext substringToIndex:start-3];
            height += [sayString sizeWithFont:[UIFont systemFontOfSize:13] constrainedToSize:CGSizeMake(235, 100) lineBreakMode:kTextLineBreakByTruncatingMiddle].height;
            NSString *tagString = [saytext substringWithRange:NSMakeRange(start, end-start)];
            
            if(![tagString isEqualToString:@""])
            {
                if(sayString.length){
                    height += 5;
                }
                NSArray *tagArray = [tagString componentsSeparatedByString:@" "];
                CGFloat height1= 0,width1 = 0;
                for(int i= 0;i<tagArray.count;i++){
                    NSString *buttonTitle = [NSString stringWithFormat:@"#%@",[tagArray objectAtIndex:i]];
                    CGFloat buttonLength = [buttonTitle sizeWithFont:[UIFont systemFontOfSize:13]].width;
                    if(width1 > 235-buttonLength){
                        width1 = 0;
                        height1 += 15;
                    }
                    width1 += buttonLength+5;
                }
                height += height1 + 17;
            }
            height += 10;
        }
        else{
            if ([[conDic valueForKey:@"mkind"] isEqualToString:@"html"]) {
                height = height+[[conDic valueForKey:@"saytext"] sizeWithFont:[UIFont systemFontOfSize:13] constrainedToSize:CGSizeMake(235, 60) lineBreakMode:kTextLineBreakByTruncatingMiddle].height+5;
            }
            else
            {
                height = height+[[conDic valueForKey:@"saytext"] sizeWithFont:[UIFont systemFontOfSize:13] constrainedToSize:CGSizeMake(235, 100) lineBreakMode:kTextLineBreakByTruncatingMiddle].height+5;
            }
            //        _textHeight += 10;
        }
        //        NSString *tel = [nearDo valueForKey:@"telno"];
        //        if(tel.length)
        //        {
        //            height += 40;
        //        }
    }
    //    else
    //    {
    NSString *tel = [nearDo valueForKey:@"telno"];
    if(tel.length)
    {
        height += 30;
    }
    if([[nearDo valueForKey:@"tourl"] length])
    {
        height +=  30;
    }
    //    }
    
    //发布内容语音和图片
    NSString *imageString = @"";
    NSString *soundString = @"";
    for(NSDictionary *aDic in [conDic valueForKey:@"attach"]){
        if([[aDic valueForKey:@"type"] isEqualToString:@"image"]){
            if(![[aDic valueForKey:@"content"]isEqualToString:@""]){
                imageString = [NSString stringWithString:[aDic valueForKey:@"content"]];
            }
        }else if([[aDic valueForKey:@"type"] isEqualToString:@"sound"]){
            if(![[aDic valueForKey:@"content"]isEqualToString:@""]){
                
                soundString = [NSString stringWithFormat:@"0,%@",[aDic valueForKey:@"content"]];
                if([aDic valueForKey:@"length"]){
                    soundString = [NSString stringWithFormat:@"%@\"",[aDic valueForKey:@"length"]];
                    
                }
            }
        }
    }
    
    if(imageString.length){
        height += 290;
        if(soundString.length){
            height +=13;
        }
        
    }
    
    height += 10;
    //回复列表
//    height += [[nearDic valueForKey:@"replylist"] count]*55;
    
    
    for(int i=0; i<[[nearDic valueForKey:@"replylist"] count]; i++){
        
        NSDictionary *_content = [AppComManager getAMsgFrom64String:[[[nearDic valueForKey:@"replylist"] objectAtIndex:i] valueForKey:@"mcontent"]];
        if([[_content valueForKey:@"saytext"]isEqualToString:@""])
        {
            //语音按钮
            height += 55;
        }
        else
        {
//            NSDictionary *_content = [AppComManager getAMsgFrom64String:[[[nearDic valueForKey:@"replylist"] objectAtIndex:i] valueForKey:@"mcontent"]];
            
            NSString *replyNameString = nil;
            if([[_content valueForKey:@"topname"] length])
            {
                replyNameString = [NSString stringWithFormat:@"RE @%@: ",[_content valueForKey:@"topname"]];
                if(replyNameString.length >18)
                {
                    replyNameString = [NSString stringWithFormat:@"RE @%@: ",[[_content valueForKey:@"topname"] substringToIndex:13]];
                }
            }
            
            NSString *sayText = [NSString stringWithFormat:@"%@%@",replyNameString,[_content valueForKey:@"saytext"]];
            float textLabelHeight = [sayText sizeWithFont:[UIFont systemFontOfSize:13] constrainedToSize:CGSizeMake(235, 100) lineBreakMode:kTextLineBreakByWordWrapping].height;
//            NSLog(@"%f",textLabelHeight);
            if(textLabelHeight>17)
            {
                textLabelHeight = textLabelHeight - 5;
            }
            height += 38+textLabelHeight;
        }

     
        

            
   }
    
    
    height += 30;
    return height;
}
#pragma mark - Table view delegate

-(void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(cell)
    {
        [(BanBu_DigiCell *)cell cancelImageLoad];
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    BanBu_DigiViewController *aDigi;
    selectedRow = indexPath.row;
    
    if(_useridBroad.length)
    {
        if(MyAppDataManager.friendDos.count < indexPath.row)
        {
            return;
        }
        aDigi  = [[BanBu_DigiViewController alloc]initWithBroadcast:[MyAppDataManager.friendDos objectAtIndex:indexPath.row]];
        aDigi.isUserBroad = YES;
    }
    else
    {
        if(MyAppDataManager.nearDos.count<indexPath.row)
        {
            return;
        }
        aDigi  = [[BanBu_DigiViewController alloc]initWithBroadcast:[MyAppDataManager.nearDos objectAtIndex:indexPath.row]];
        aDigi.isUserBroad = NO;
    }
    aDigi.selectSection = indexPath.row;
    aDigi.hidesBottomBarWhenPushed = YES;
    [self.leveyTabBarController hidesTabBar:YES animated:YES];
    [self.navigationController pushViewController:aDigi animated:YES];
    [aDigi release];
    
}

//查看个人资料
-(void)seeProfile:(UIButton *)sender{
    NSArray *messageArr = [sender.titleLabel.text componentsSeparatedByString:@"-"];
    NSDictionary *aDic = nil;
    if(messageArr.count == 1){
        if(!_useridBroad.length)
        {
            aDic = [NSDictionary dictionaryWithDictionary:[MyAppDataManager.nearDos objectAtIndex:[[messageArr objectAtIndex:0] intValue]]];
        }
        else
        {
            aDic = [NSDictionary dictionaryWithDictionary:[MyAppDataManager.friendDos objectAtIndex:[[messageArr objectAtIndex:0] intValue]]];
            
        }
        
        BanBu_PersonDataViewController *peopleFfofile = [[BanBu_PersonDataViewController alloc] initWithProfile:[aDic valueForKey:keyPersonalInfo]];
        peopleFfofile.hidesBottomBarWhenPushed = YES;
        [self.leveyTabBarController hidesTabBar:YES animated:YES];
        
        [self.navigationController pushViewController:peopleFfofile animated:YES];
        [peopleFfofile release];
    }else if(messageArr.count == 2){
        NSArray *replyList = nil;
        if(!_useridBroad.length)
        {
            replyList = [NSArray arrayWithArray:[[MyAppDataManager.nearDos objectAtIndex:[[messageArr objectAtIndex:0] intValue]] valueForKey:@"replylist"]];
        }
        else
        {
            replyList = [NSArray arrayWithArray:[[MyAppDataManager.friendDos objectAtIndex:[[messageArr objectAtIndex:0] intValue]] valueForKey:@"replylist"]];
            
        }
        aDic = [NSDictionary dictionaryWithDictionary:[replyList objectAtIndex:[[messageArr objectAtIndex:1] intValue]]];
    
        BanBu_PersonDataViewController *peopleFfofile = [[BanBu_PersonDataViewController alloc] initWithProfile:aDic];
//        [peopleFfofile getMyInfo];
        peopleFfofile.hidesBottomBarWhenPushed = YES;
        [self.leveyTabBarController hidesTabBar:YES animated:YES];
        [self.navigationController pushViewController:peopleFfofile animated:YES];
        [peopleFfofile release];
    }
    
}

// 语音的播放及动画
-(void)animation:(UIButton *)animationBtn
{
    
    if(animationBackgroundView){
        [animationBackgroundView removeFromSuperview];
    }
    
    NSArray *voiceArr = [_voiceButton.titleLabel.text componentsSeparatedByString:@","];
    if([[voiceArr objectAtIndex:0] boolValue]){
        animationBackgroundView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 60, 25)];
        animationBackgroundView.userInteractionEnabled = YES;
        [animationBackgroundView setImage:[UIImage imageNamed:@"广播详情-复选框-播放_空.png"]];
    }else{
        animationBackgroundView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 105, 26)];
        animationBackgroundView.backgroundColor = [UIColor clearColor];
        animationBackgroundView.userInteractionEnabled = YES;
        
        [animationBackgroundView setImage:[UIImage imageNamed:@"播放语音_未按下.png"]];
        
    }
    
    
    NSArray *animationImages = [NSArray arrayWithObjects:@"feed_comment_player_pause_anim1.png",@"feed_comment_player_pause_anim2.png",@"feed_comment_player_pause_anim3.png", nil];
    NSMutableArray *images = [NSMutableArray arrayWithCapacity:3];
    for(NSString *path in animationImages)
    {
        [images addObject:[UIImage imageNamed:path]];
    }
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectZero];
    if([[voiceArr objectAtIndex:0] boolValue]){
        
        imageView.frame = CGRectMake(13, 6.5, 10, 12);
        
    }else{
        imageView.frame = CGRectMake(24, 7, 10, 12);
        
    }
    imageView.userInteractionEnabled = YES;
    imageView.animationImages = images;
    imageView.animationDuration = 1.0;
    imageView.animationImages = images;
    imageView.animationDuration = 1.0;
    
    imageView.backgroundColor = [UIColor clearColor];
    [animationBackgroundView addSubview:imageView];
    [imageView startAnimating];
    [imageView release];
    
    [animationBtn addSubview:animationBackgroundView];
    
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(stopPlay:)];
    [animationBackgroundView addGestureRecognizer:tap];
    [tap release];
    
    
}

-(void)stopPlay:(UITapGestureRecognizer *)tap{
    [_player stop];
    displayCell = -1;
    [tap.view removeFromSuperview];
    
    
}

-(void)playVoiceButton:(UIButton *)sender{
    _voiceButton = sender;
    displayCell = sender.tag - 999;
    NSArray *voiceArr = [_voiceButton.titleLabel.text componentsSeparatedByString:@","];
    if(![FileManager fileExistsAtPath:[AppComManager pathForMedia:[voiceArr lastObject]]]){
        [AppComManager getBanBuMedia:[voiceArr lastObject] delegate:self];
        [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"loadingNotice", nil) activityAnimated:YES];
    }else{
        if(_player){
            [_player release],_player = nil;
        }
        //        NSLog(@"%@",[AppComManager pathForMedia:[voiceArr lastObject]]);
        NSData *aData = [NSData dataWithContentsOfFile:[AppComManager pathForMedia:[voiceArr lastObject]]];
        _player = [[AVAudioPlayer alloc]initWithData:aData error:nil];
        _player.delegate = self;
        _player.volume = 1.0;
        [_player prepareToPlay];
        [_player play];
        [_playHUD startAnimating];
        if([_player isPlaying]){
            [self animation:sender];
        }
    }
}

//下载语音

#pragma mark - BanBuDownloadRequest

- (void)banbuDownloadRequest:(NSDictionary *)resDic didFinishedWithError:(NSError *)error{
    
    NSArray *voiceArr = [_voiceButton.titleLabel.text componentsSeparatedByString:@","];
    
    [TKLoadingView dismissTkFromView:self.navigationController.view animated:NO afterShow:0.0];
    if([[resDic valueForKey:@"ok"]boolValue]){
        if(_player){
            [_player release],_player = nil;
        }
        //        NSLog(@"%@",[AppComManager pathForMedia:[voiceArr lastObject]]);
        NSData *aData = [NSData dataWithContentsOfFile:[AppComManager pathForMedia:[voiceArr lastObject]]];
        _player = [[AVAudioPlayer alloc]initWithData:aData error:nil];
        _player.delegate = self;
        _player.volume = 1.0;
        [_player prepareToPlay];
        [_player play];
        [_playHUD startAnimating];
        if([_player isPlaying]){
            [self animation:_voiceButton];
        }
        //        if(_player){
        //            [_player release],_player = nil;
        //        }
    }else{
        //        [  showTkloadingAddedTo:self.view title:@"下载失败" activityAnimated:NO duration:1.0];
    }
}

//播放完毕

-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{
    [_player stop];
    displayCell = -1;
    [[_voiceButton.subviews lastObject]removeFromSuperview];
}

//加载数据

-(void)loadingData{
    segmentController.userInteractionEnabled = NO;
    
    if([self.view viewWithTag:100]){
        [[self.view viewWithTag:100]removeFromSuperview];
        [[self.view viewWithTag:101]removeFromSuperview];
        [[self.view viewWithTag:102]removeFromSuperview];
        
    }
    if(_isLoadingRefresh){
        [AppLocationManager getMyLocation];
        _DosPage = 1;
    }else{
        if(_DosPage ==1)
        {
            _DosPage =3;
        }
        else
            _DosPage++;
    }
    
    if(_useridBroad.length)
    {
        NSMutableDictionary *sendDic = [NSMutableDictionary dictionary];
        [sendDic setValue:_useridBroad forKey:@"frienduid"];
        [sendDic setValue:[NSString stringWithFormat:@"%i",_DosPage] forKey:PageNo];
        [sendDic setValue:[MyAppDataManager getLanguageSubmitToServer] forKey:@"lang"];
        [TKLoadingView showTkloadingAddedTo:self.view point:CGPointMake(160, 70) title:NSLocalizedString(@"loadingNotice", nil) activityAnimated:YES];
        [AppComManager getBanBuData:BanBu_Get_Friend_FriendDo par:sendDic delegate:self];
        return;
        
    }
    NSMutableDictionary *parDic = [NSMutableDictionary dictionary];
    [parDic setValue:[NSString stringWithFormat:@"%.f",AppLocationManager.curLocation.latitude*1000000] forKey:Latitude];
    [parDic setValue:[NSString stringWithFormat:@"%.f",AppLocationManager.curLocation.longitude*1000000] forKey:Longitude];
    [parDic setValue:[NSString stringWithFormat:@"%i",_DosPage] forKey:PageNo];
    [parDic setValue:self.keywordString forKey:@"keyword"];
    [parDic setValue:[MyAppDataManager getLanguageSubmitToServer] forKey:@"lang"];

    
    if(segmentController.selectedIndex==1)
    {
        [MyAppDataManager.unReadBroadInfor setValue:@"0" forKey:@"h"];
        [MyAppDataManager.unReadBroadInfor setValue:@"0" forKey:@"f"];
        [self updateBroadcastBadgeValue];
        [AppComManager getBanBuData:BanBu_Get_Friend_FriendDos_Broadcast par:parDic delegate:self];
        
    }
    else
    {
        [MyAppDataManager.unReadBroadInfor setValue:@"0" forKey:@"z"];
        [self updateBroadcastBadgeValue];
        [AppComManager getBanBuData:BanBu_Get_User_Neardo par:parDic delegate:self];

    }
}
-(void)setSegmentUserInterface
{
    segmentController.userInteractionEnabled = YES;
}
#pragma mark - BanBuRequetDelegate

- (void)banbuRequestDidFinished:(NSDictionary *)resDic error:(NSError *)error
{

    NSLog(@"%@",resDic);
    NSLog(@"success");
    
    //zyfzyfzyf⬇️解析数据并存储到_dataArray
    NSArray * listArray=[resDic valueForKey:@"list"];
    for (NSDictionary * dic in listArray) {
        NSString * mcontentStr=[[dic valueForKey:@"actioninfor"] valueForKey:@"mcontent"];
        NSData * dicData=[NSData dataFromBase64String:mcontentStr];
        NSDictionary *mcontentDic=[NSDictionary dictionaryWithJSONData:dicData error:nil];
        NSMutableDictionary * actionDic=[NSMutableDictionary dictionaryWithDictionary:[dic valueForKey:@"actioninfor"] ];
        [actionDic setValue:mcontentDic forKey:@"mcontent"];
        NSMutableDictionary * dataDic=[[NSMutableDictionary alloc]initWithDictionary:dic];
        [dataDic setValue:actionDic forKey:@"actioninfor"];
        [_dataArray addObject:dataDic];
    }
    //zyfzyfzyf⬆️

    isLoading = NO;
    self.view.userInteractionEnabled = YES;
    self.navigationController.view.userInteractionEnabled =YES;
    [TKLoadingView dismissTkFromView:self.view animated:YES afterShow:0.0];
    [TKLoadingView dismissTkFromView:self.navigationController.view animated:YES afterShow:0.0];
    if([AppComManager respondsDic:resDic isFunctionData:BanBu_Get_User_Neardo]||[AppComManager respondsDic:resDic isFunctionData:BanBu_Get_Friend_FriendDos_Broadcast])
    {
        [self performSelector:@selector(setSegmentUserInterface) withObject:nil afterDelay:0.7];
    }
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    //更新本地时间与服务器时间的时间差
    if([[resDic valueForKey:@"servertime"] length])
    {
        MyAppDataManager.timeDifference = [[formatter dateFromString:[NSString stringWithFormat:@"%@",[resDic valueForKey:@"servertime"]]] timeIntervalSinceNow];
        [UserDefaults setObject:[NSNumber numberWithDouble:MyAppDataManager.timeDifference] forKey:@"timedifference"];
    }
    else
    {
        MyAppDataManager.timeDifference = [[UserDefaults valueForKey:@"timedifference"] doubleValue];
    }
    [formatter release];
    if(error)
    {
        [TKLoadingView showTkloadingAddedTo:self.view title:NSLocalizedString(@"network_error", nil) activityAnimated:NO duration:2.0];
        [loadingView stopAnimating];
        lab.text = NSLocalizedString(@"network_error", nil);
        if(_DosPage>3)
        {
            _DosPage--;
        }
        else
        {
            _DosPage =1;
        }
        isLoading = NO;
        if(!_useridBroad.length)
            [self finishedLoading];
        return;
    }
   
    if([AppComManager respondsDic:resDic isFunctionData:BanBu_Get_User_Neardo]||[AppComManager respondsDic:resDic isFunctionData:BanBu_Get_Friend_FriendDos_Broadcast]){
        
         dispatch_async(dispatch_get_global_queue(0, 0), ^{
             @autoreleasepool {
                 
        if([[resDic valueForKey:@"ok"] boolValue])
        {
            
            
                NSNumber * number = [NSNumber numberWithInt:[[resDic valueForKey:@"getscore"] integerValue]];
                dispatch_sync(dispatch_get_main_queue(), ^{
                    [MyAppDataManager showGoldView:number andView:self.navigationController.view];
                });
                
                NSArray *reportArr =  [UserDefaults valueForKey:@"reportList"];
                __block NSMutableArray *saveArr = [[NSMutableArray alloc]initWithArray:MyAppDataManager.nearDos];
                if(_isLoadingRefresh)
                {
                    
                    [BanBu_RefreshTime getCurrentTime:@"squares_updateTime"];
                    
                    
                    
                    if([AppComManager respondsDic:resDic isFunctionData:BanBu_Get_User_Neardo])
                    {
                        //保存最后看陌生人广播的时间
                        NSString *timeString = [MyAppDataManager getServerTime];
                        [UserDefaults setValue:timeString forKey:KeyLastSeeMoDynamicTime];
                    }
                    else
                    {
                        //保存最后看好友广播的时间
                        NSString *timeString = [MyAppDataManager getServerTime];
                        [UserDefaults setValue:timeString forKey:KeyLastSeeFriendDynamicTime];
                    }
                    
                    
                    
                    [_existDic removeAllObjects];
                    [cacheArray removeAllObjects];
                    [MyAppDataManager.nearDos removeAllObjects];
                    dispatch_sync(dispatch_get_main_queue(), ^{
                        if(segmentController.selectedIndex==0)
                        {
                                [UIView animateWithDuration:0.5 animations:^{
                                    //隐藏搜索
                                    /*
                                     self.tableView.tableHeaderView = searchView;
                                     */
                            }];
                        }
                        else
                        {
                                [UIView animateWithDuration:0.5 animations:^{
                                self.tableView.tableHeaderView = nil;
                            }];
                        }
                    });
                    NSString *flistString = [NSString stringWithFormat:@",%@,%@,",[[[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"friendlist"] valueForKey:@"x"],[[[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"friendlist"] valueForKey:@"z"]];
                    //对名字和话，进行替换后，在存储
                    for(int i=0;i<[[resDic valueForKey:@"list"]count];i++)
                    {
                        NSMutableDictionary *aDic = [NSMutableDictionary dictionaryWithDictionary:[[resDic valueForKey:@"list"] objectAtIndex:i]];
                        //先解开base64的“mcontent”，然后替换多语言和备注名字
                        NSMutableDictionary *conDic = [[NSMutableDictionary alloc]initWithDictionary:[aDic valueForKey:@"actioninfor"]];
                        NSMutableDictionary *mcontentDic = [NSMutableDictionary dictionaryWithDictionary:[AppComManager getAMsgFrom64String:[conDic valueForKey:@"mcontent"]]];
                        [_existDic setObject:[NSNumber numberWithBool:YES] forKey:[aDic valueForKey:@"actid"]];
                        [mcontentDic setValue:[MyAppDataManager IsInternationalLanguage:[mcontentDic valueForKey:@"saytext"]] forKey:@"saytext"];
                        [conDic setValue:mcontentDic  forKey:@"mcontent"];
                        [aDic setValue:conDic forKey:@"actioninfor"];
                        [conDic release];
                        NSMutableDictionary *userDic = [[NSMutableDictionary alloc] initWithDictionary:[aDic valueForKey:@"userinfor"]];
                        
                        if([MyAppDataManager theRevisedName:[[aDic valueForKey:@"userinfor"]valueForKey:@"pname"] andUID:[aDic valueForKey:@"userid"]])
                        {
                            [userDic setObject:[MyAppDataManager theRevisedName:[userDic valueForKey:@"pname"] andUID:[aDic valueForKey:@"userid"]] forKey:@"pname"];
                            [aDic setValue:userDic forKey:@"userinfor"];
                        }
                        [userDic release];
                        //解回复列表里的"mcontent",
                        //被举报的广播不显示。
                        
                        //                    NSLog(@"%@",aDic);
                        BOOL isBlack = NO;
                        if([flistString rangeOfString:[NSString stringWithFormat:@",%@,",[aDic valueForKey:@"userid"]]].location != NSNotFound&&flistString.length)
                        {
                            isBlack = YES;
                        }
                        
                        BOOL isReported = NO;
                        if(reportArr.count){
                            for(NSString *reportStr in reportArr){
                                if([reportStr isEqualToString:[aDic valueForKey:@"actid"]]){
                                    isReported = YES;
                                    break;
                                }
                            }
                        }
                        
                        if(!isReported&&!isBlack){
                            if(i<20)
                                [MyAppDataManager.nearDos addObject:aDic];
                            else
                                [cacheArray addObject:aDic];
                            
                        }
                    }
                    dispatch_sync(dispatch_get_main_queue(), ^{

                    if(cryImageView || noticeLabel){
                        [[self.view viewWithTag:100]removeFromSuperview];
                        [[self.view viewWithTag:101]removeFromSuperview];
                        [[self.view viewWithTag:102]removeFromSuperview];
                    }
                    });
                    if(!MyAppDataManager.nearDos.count&&!_useridBroad.length)
                    {
                        dispatch_sync(dispatch_get_main_queue(), ^{
                        NSString *str = [NSString stringWithFormat:@"%@",self.tableView.observationInfo];
                        if(str.length&&[str rangeOfString:@"contentOffset"].location != NSNotFound)
                            [self.tableView removeObserver:self forKeyPath:@"contentOffset"];
                        
                        cryImageView = [[UIImageView alloc]initWithFrame:CGRectMake(136,  100, 48, 48)];
                        cryImageView.tag = 100;
                        cryImageView.image = [UIImage imageNamed:@"cry.png"];
                        [self.tableView addSubview:cryImageView];
                        [cryImageView release];
                            if(!_useridBroad.length)
                            {
                        noticeLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 150, 300, 100)];
                        noticeLabel.tag = 101;
                        noticeLabel.numberOfLines = 0;
                        noticeLabel.text = NSLocalizedString(@"noticeLabel1", nil);
                        noticeLabel.textColor = [UIColor darkGrayColor];
                        
                        noticeLabel.font = [UIFont systemFontOfSize:16];
                        noticeLabel.textAlignment = kTextAlignmentCenter;
                        noticeLabel.backgroundColor = [UIColor clearColor];
                        [self.tableView addSubview:noticeLabel];
                        [noticeLabel release];
                        
                        
                        footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 230, 320, 100)];
                        footerView.backgroundColor = [UIColor clearColor];
                        footerView.tag = 102;
                        [self.tableView addSubview:footerView];
                        [footerView release];
                        
 
                            UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
                            searchBtn.frame = CGRectMake(15, 0, 290, 40);
                            [searchBtn setBackgroundImage:[[UIImage imageNamed:@"app_btn_blue.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
                            [searchBtn setTitle:NSLocalizedString(@"listButton", nil) forState:UIControlStateNormal];
                            [searchBtn addTarget:self action:@selector(releaseRadio) forControlEvents:UIControlEventTouchUpInside];
                            [footerView addSubview:searchBtn];
                        }
                        //                    [self.tableView setScrollEnabled:NO];
                        self.tableView.tableFooterView = nil;
                        
                        [self.tableView reloadData];
                        });
                    }
                    
                    else
                    {
                        
                        
                        __block NSMutableArray *saveArr = [[NSMutableArray alloc] initWithArray:MyAppDataManager.nearDos];
                        
                        //                        dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
                        //                        dispatch_async(queue, ^{
                        NSData *broadcastData = [NSKeyedArchiver archivedDataWithRootObject:saveArr];
                        NSString *path = [DataCachePath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@-broadcastdata",MyAppDataManager.useruid]];
                        [broadcastData writeToFile:path atomically:YES];
                        //                        });
                        
                        [MyAppDataManager writePersonalDataToDB:saveArr];
                        
                        [saveArr release];
                        //                    });
                        dispatch_sync(dispatch_get_main_queue(), ^{
                            [self.tableView reloadData];
                            self.tableView.tableFooterView = moreView;
                            [self.tableView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:self.tableView];
                        });
                        
                        
                        
                        
                        
                        //                    [self.tableView setScrollEnabled:YES];
                    }
                    dispatch_sync(dispatch_get_main_queue(), ^{
                        [self finishedLoading]; });
                }
                else
                {
                    NSMutableArray *filterArr = [NSMutableArray arrayWithArray:[resDic valueForKey:@"list"]];
                    NSMutableArray *congfuArr = [NSMutableArray array];
                    for(int i=0;i<[[resDic valueForKey:@"list"] count];i++)
                    {
                        //被举报的广播不显示。
                        BOOL isReported = NO;
                        if(reportArr.count){
                            for(NSString *reportStr in reportArr){
                                if([reportStr isEqualToString:[[filterArr objectAtIndex:i] valueForKey:@"actid"]]){
                                    isReported = YES;
                                    break;
                                }
                            }
                        }
                        if(isReported){
                            [congfuArr addObject:[filterArr objectAtIndex:i]];
                        }
                        //修改去重
                        if(_existDic&&[_existDic valueForKey:[[filterArr objectAtIndex:i] valueForKey:@"actid"]])
                        {
                            [congfuArr addObject:[filterArr objectAtIndex:i]];
                        }
                        else
                        {
                            NSMutableDictionary *aDic = [NSMutableDictionary dictionaryWithDictionary:[[resDic valueForKey:@"list"] objectAtIndex:i]];
                            NSMutableDictionary *conDic = [[NSMutableDictionary alloc]initWithDictionary:[aDic valueForKey:@"actioninfor"]];
                            NSMutableDictionary *mcontentDic = [NSMutableDictionary dictionaryWithDictionary:[AppComManager getAMsgFrom64String:[conDic valueForKey:@"mcontent"]]];
                            [mcontentDic setValue:[MyAppDataManager IsInternationalLanguage:[mcontentDic valueForKey:@"saytext"]] forKey:@"saytext"];
                            [conDic setValue:mcontentDic forKey:@"mcontent"];
                            [aDic setValue:conDic forKey:@"actioninfor"];
                            [conDic release];
                            
                            NSMutableDictionary *userDic = [[NSMutableDictionary alloc] initWithDictionary:[aDic valueForKey:@"userinfor"]];
                            
                            if([MyAppDataManager theRevisedName:[userDic valueForKey:@"pname"] andUID:[aDic valueForKey:@"userid"]]){
                                [userDic setObject:[MyAppDataManager theRevisedName:[userDic valueForKey:@"pname"] andUID:[aDic valueForKey:@"userid"]] forKey:@"pname"];
                                [aDic setValue:userDic forKey:@"userinfor"];
                            }
                            [userDic release];
                            
                            [filterArr replaceObjectAtIndex:i withObject:aDic];
                        }
                        [_existDic setObject:[NSNumber numberWithBool:YES] forKey:[[filterArr objectAtIndex:i] valueForKey:@"actid"]];
                    }
                    [cacheArray removeAllObjects];
                    [filterArr removeObjectsInArray:congfuArr];
                    [cacheArray addObjectsFromArray:filterArr];
                    if(!cacheArray.count)
                    {
                        dispatch_sync(dispatch_get_main_queue(), ^{
                            [loadingView stopAnimating];
                            _DosPage--;
                            lab.text = NSLocalizedString(@"noData", nil);});
                    }
                }
                if(!alreadyRefresh&&isLoading&&cacheArray.count)
                {
                    dispatch_sync(dispatch_get_main_queue(), ^{
                        [self startLoadNextPage];
                        [self loadingData];});
                }
                [MyAppDataManager writePersonalDataToDB:saveArr];
            
            
            
            
        }
        else
        {
            if(_isLoadingRefresh)
            {
                dispatch_sync(dispatch_get_main_queue(), ^{
                [MyAppDataManager.nearDos removeAllObjects];
                cryImageView = [[UIImageView alloc]initWithFrame:CGRectMake(136, 100, 48, 48)];
                cryImageView.tag = 100;
                cryImageView.image = [UIImage imageNamed:@"cry.png"];
                [self.tableView addSubview:cryImageView];
                [cryImageView release];
                    if(!_useridBroad.length)
                    {
                noticeLabel = [[UILabel alloc]initWithFrame:CGRectMake(10,150, 300, 100)];
                noticeLabel.tag = 101;
                noticeLabel.numberOfLines = 0;
                noticeLabel.text = NSLocalizedString(@"noticeLabel1", nil);
                noticeLabel.textColor = [UIColor darkGrayColor];
                noticeLabel.font = [UIFont systemFontOfSize:16];
                noticeLabel.textAlignment = kTextAlignmentCenter;
                noticeLabel.backgroundColor = [UIColor clearColor];
                [self.tableView addSubview:noticeLabel];
                [noticeLabel release];
                
                footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 230, 320, 100)];
                footerView.backgroundColor = [UIColor clearColor];
                footerView.tag = 102;
                [self.tableView addSubview:footerView];
                [footerView release];

                    UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
                    searchBtn.frame = CGRectMake(15, 0, 290, 40);
                    [searchBtn setBackgroundImage:[[UIImage imageNamed:@"app_btn_blue.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
                    [searchBtn setTitle:NSLocalizedString(@"listButton", nil) forState:UIControlStateNormal];
                    [searchBtn addTarget:self action:@selector(releaseRadio) forControlEvents:UIControlEventTouchUpInside];
                    [footerView addSubview:searchBtn];
                }
                self.tableView.tableFooterView = nil;
                //                [self.tableView setScrollEnabled:NO];
                
                [self finishedLoading];
                [self.tableView reloadData];
                 });
            }
            if(!alreadyRefresh&&isLoading)
            {
                dispatch_sync(dispatch_get_main_queue(), ^{
                [loadingView stopAnimating];
                });
                if(_DosPage>3)
                {
                    _DosPage--;
                }
                else
                {
                    _DosPage =1;
                }
                
                lab.text = NSLocalizedString(@"noData", nil);
            }
        }
             }
        });
    }
    
    else if([AppComManager respondsDic:resDic isFunctionData:BanBu_Delete_Broadcast])
    {
        if([[resDic valueForKey:@"ok"] boolValue])
        {
            if(_useridBroad)
            {
                [MyAppDataManager.friendDos removeObjectAtIndex:selectedRow];
                
            }
            else
            {
                [MyAppDataManager.nearDos removeObjectAtIndex:selectedRow];
                
            }
            [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:selectedRow inSection:0]] withRowAnimation:UITableViewRowAnimationTop];
         
        }
        [self finishedLoading];
    }
    else if([AppComManager respondsDic:resDic isFunctionData:BanBu_Get_Broad_Hotkey])
    {
        hotKeyArr = [[resDic valueForKey:@"list"] retain];
        
        [self buildHotKeyView];
    }
    else if([AppComManager respondsDic:resDic isFunctionData:BanBu_Get_Friend_FriendDo])
    {
        {
            dispatch_async(dispatch_get_global_queue(0, 0), ^{
                if([[resDic valueForKey:@"ok"] boolValue])
                {
                    
                   if(_DosPage == 1)
                    {
                        [cacheArray removeAllObjects];
                        [MyAppDataManager.friendDos removeAllObjects];
                        for(int i=0;i<[[resDic valueForKey:@"list"]count];i++)
                        {
                            NSMutableDictionary *aDic = [NSMutableDictionary dictionaryWithDictionary:[[resDic valueForKey:@"list"] objectAtIndex:i]];
                            //先解开base64的“mcontent”，然后替换多语言和备注名字
                            NSMutableDictionary *conDic = [[NSMutableDictionary alloc]initWithDictionary:[aDic valueForKey:@"actioninfor"]];
                            NSMutableDictionary *mcontentDic = [NSMutableDictionary dictionaryWithDictionary:[AppComManager getAMsgFrom64String:[conDic valueForKey:@"mcontent"]]];
                            [_existDic setObject:[NSNumber numberWithBool:YES] forKey:[aDic valueForKey:@"actid"]];
                            [mcontentDic setValue:[MyAppDataManager IsInternationalLanguage:[mcontentDic valueForKey:@"saytext"]] forKey:@"saytext"];
                            [conDic setValue:mcontentDic  forKey:@"mcontent"];
                            [aDic setValue:conDic forKey:@"actioninfor"];
                            [conDic release];
                                if(i<20)
                                    [MyAppDataManager.friendDos addObject:aDic];
                                else
                                    [cacheArray addObject:aDic];
                            }
                        
                        dispatch_sync(dispatch_get_main_queue(), ^{
                            
                            if(cryImageView || noticeLabel){
                                [[self.view viewWithTag:100]removeFromSuperview];
                                [[self.view viewWithTag:101]removeFromSuperview];
                                [[self.view viewWithTag:102]removeFromSuperview];
                            }
                        });
                        if(!MyAppDataManager.friendDos.count&&_useridBroad.length)
                        {
                            dispatch_sync(dispatch_get_main_queue(), ^{
                                NSString *str = [NSString stringWithFormat:@"%@",self.tableView.observationInfo];
                                if(str.length&&[str rangeOfString:@"contentOffset"].location != NSNotFound)
                                    [self.tableView removeObserver:self forKeyPath:@"contentOffset"];
                                cryImageView = [[UIImageView alloc]initWithFrame:CGRectMake(136, self.tableView.frame.size.height/2.0 - 24, 48, 48)];
                                cryImageView.tag = 100;
                                cryImageView.image = [UIImage imageNamed:@"cry.png"];
                                [self.tableView addSubview:cryImageView];
                                [cryImageView release];
                                //2014年10月29日12:02:42 by yinlinlin如果是个人空间，位置需要改动
                                if (self.tableView.tableHeaderView)
                                {
                                    [cryImageView setFrame:CGRectMake(136, self.tableView.frame.size.height/2.0 + 124, 48, 48)];
                                }
                                
                                if(!_useridBroad.length)
                                {
                                noticeLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, __MainScreen_Height - 150, 300, 100)];
                                noticeLabel.tag = 101;
                                noticeLabel.numberOfLines = 0;
                                noticeLabel.text = NSLocalizedString(@"noticeLabel1", nil);
                                noticeLabel.textColor = [UIColor darkGrayColor];
                                
                                noticeLabel.font = [UIFont systemFontOfSize:16];
                                noticeLabel.textAlignment = kTextAlignmentCenter;
                                noticeLabel.backgroundColor = [UIColor clearColor];
                                [self.tableView addSubview:noticeLabel];
                                [noticeLabel release];
                                
                                
                                footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 230, 320, 100)];
                                footerView.backgroundColor = [UIColor clearColor];
                                footerView.tag = 102;
                                [self.tableView addSubview:footerView];
                                [footerView release];
            
                                    UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
                                    searchBtn.frame = CGRectMake(15, 0, 290, 40);
                                    [searchBtn setBackgroundImage:[[UIImage imageNamed:@"app_btn_blue.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
                                    [searchBtn setTitle:NSLocalizedString(@"listButton", nil) forState:UIControlStateNormal];
                                    [searchBtn addTarget:self action:@selector(releaseRadio) forControlEvents:UIControlEventTouchUpInside];
                                    [footerView addSubview:searchBtn];
                                }

                                //                    [self.tableView setScrollEnabled:NO];
                                self.tableView.tableFooterView = nil;
                               
                                [self.tableView reloadData];
                            });
                        }
                        
                        else
                        {
                            
                            
                            dispatch_sync(dispatch_get_main_queue(), ^{
                                [self.tableView reloadData];
                                self.tableView.tableFooterView = moreView;
                                [self.tableView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:self.tableView];
                            });
                            
                        }
                        dispatch_sync(dispatch_get_main_queue(), ^{
                            [self finishedLoading]; });
                    }
                    else
                    {
                        NSMutableArray *filterArr = [NSMutableArray arrayWithArray:[resDic valueForKey:@"list"]];
                        for(int i=0;i<[[resDic valueForKey:@"list"] count];i++)
                        {
                                   NSMutableDictionary *aDic = [NSMutableDictionary dictionaryWithDictionary:[[resDic valueForKey:@"list"] objectAtIndex:i]];
                                NSMutableDictionary *conDic = [[NSMutableDictionary alloc]initWithDictionary:[aDic valueForKey:@"actioninfor"]];
                                NSMutableDictionary *mcontentDic = [NSMutableDictionary dictionaryWithDictionary:[AppComManager getAMsgFrom64String:[conDic valueForKey:@"mcontent"]]];
                                [mcontentDic setValue:[MyAppDataManager IsInternationalLanguage:[mcontentDic valueForKey:@"saytext"]] forKey:@"saytext"];
                                [conDic setValue:mcontentDic forKey:@"mcontent"];
                                [aDic setValue:conDic forKey:@"actioninfor"];
                                [conDic release];
                                

                            
                                [filterArr replaceObjectAtIndex:i withObject:aDic];
                        }
                        [cacheArray removeAllObjects];
                        [cacheArray addObjectsFromArray:filterArr];
                        if(!cacheArray.count)
                        {
                            dispatch_sync(dispatch_get_main_queue(), ^{
                                [loadingView stopAnimating];
                                _DosPage--;
                                lab.text = NSLocalizedString(@"noData", nil);});
                        }
                    }
                    if(!alreadyRefresh&&isLoading&&cacheArray.count)
                    {
                        dispatch_sync(dispatch_get_main_queue(), ^{
                            [self startLoadNextPage];
                            [self loadingData];});
                    }
                }
                else
                {
                    if(_isLoadingRefresh)
                    {
                        dispatch_sync(dispatch_get_main_queue(), ^{
                            [MyAppDataManager.friendDos removeAllObjects];
                            cryImageView = [[UIImageView alloc]initWithFrame:CGRectMake(136, 100, 48, 48)];
                            cryImageView.tag = 100;
                            cryImageView.image = [UIImage imageNamed:@"cry.png"];
                            [self.tableView addSubview:cryImageView];
                            [cryImageView release];
                            if(!_useridBroad.length)
                            {
                            noticeLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 150, 300, 100)];
                            noticeLabel.tag = 101;
                            noticeLabel.numberOfLines = 0;
                            noticeLabel.text = NSLocalizedString(@"noticeLabel1", nil);
                            noticeLabel.textColor = [UIColor darkGrayColor];
                            noticeLabel.font = [UIFont systemFontOfSize:16];
                            noticeLabel.textAlignment = kTextAlignmentCenter;
                            noticeLabel.backgroundColor = [UIColor clearColor];
                            [self.tableView addSubview:noticeLabel];
                            [noticeLabel release];
                            
                            footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 230, 320, 100)];
                            footerView.backgroundColor = [UIColor clearColor];
                            footerView.tag = 102;
                            [self.tableView addSubview:footerView];
                            [footerView release];
                            
               
                                UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
                                searchBtn.frame = CGRectMake(15, 0, 290, 40);
                                [searchBtn setBackgroundImage:[[UIImage imageNamed:@"app_btn_blue.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
                                [searchBtn setTitle:NSLocalizedString(@"listButton", nil) forState:UIControlStateNormal];
                                [searchBtn addTarget:self action:@selector(releaseRadio) forControlEvents:UIControlEventTouchUpInside];
                                [footerView addSubview:searchBtn];
                            }
                            self.tableView.tableFooterView = nil;
                            //                [self.tableView setScrollEnabled:NO];
                            [self finishedLoading];
                            [self.tableView reloadData];
                        });
                    }
                    if(!alreadyRefresh&&isLoading)
                    {
                        dispatch_sync(dispatch_get_main_queue(), ^{
                            [loadingView stopAnimating];
                        });
                        if(_DosPage>3)
                        {
                            _DosPage--;
                        }
                        else
                        {
                            _DosPage =1;
                        }
                        
                        lab.text = NSLocalizedString(@"noData", nil);
                    }
                }
            });
        }

    }
    
    
}

-(void)searchFar:(UIButton *)sender{
    
    if(sender.tag == 1000){
        farDemeter = @"500000";
        //        sender.
    }else if(sender.tag == 1001){
        farDemeter = @"2000000";
    }
    [self setRefreshing];
}
-(void)startLoadNextPage
{
    if(_useridBroad)
    {
        if(cacheArray.count)
        {
            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[MyAppDataManager.friendDos count] inSection:0];
            [MyAppDataManager.friendDos addObjectsFromArray:cacheArray];
            [cacheArray removeAllObjects];
                [UIView animateWithDuration:0.5 animations:^{
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self.tableView reloadData];
                    [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
                });
            }];
            alreadyRefresh = YES;
        }
        if(!cacheArray.count)
        {
            [self loadingData];
            isLoading = YES;
        }

    }
    else
    {
        if(cacheArray.count)
        {
            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[MyAppDataManager.nearDos count] inSection:0];
            [MyAppDataManager.nearDos addObjectsFromArray:cacheArray];
            [cacheArray removeAllObjects];
                [UIView animateWithDuration:0.5 animations:^{
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self.tableView reloadData];
                    [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
                });
            }];
            alreadyRefresh = YES;
        }
        if(!cacheArray.count)
        {
            [self loadingData];
            segmentController.userInteractionEnabled = NO;
            isLoading = YES;
        }

    }
    
}

#pragma show and hide the keyboard
- (void)setUpForDismissKeyboard {
    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
    UITapGestureRecognizer *singleTapGR =
    [[UITapGestureRecognizer alloc] initWithTarget:self
                                            action:@selector(tapAnywhereToDismissKeyboard:)];
    NSOperationQueue *mainQuene =[NSOperationQueue mainQueue];
    [nc addObserverForName:UIKeyboardWillShowNotification
                    object:nil
                     queue:mainQuene
                usingBlock:^(NSNotification *note){
                    [self.view addGestureRecognizer:singleTapGR];
                }];
    [nc addObserverForName:UIKeyboardWillHideNotification
                    object:nil
                     queue:mainQuene
                usingBlock:^(NSNotification *note){
                    [self.view removeGestureRecognizer:singleTapGR];
                }];
}

- (void)tapAnywhereToDismissKeyboard:(UIGestureRecognizer *)gestureRecognizer {
    //此method会将self.view里所有的subview的first responder都resign掉
    [self.view endEditing:YES];
}
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if([keyPath isEqual:@"contentOffset"])
    {
        if(self.tableView.contentOffset.y>self.tableView.contentSize.height-__MainScreen_Height+44+30&&self.tableView.contentSize.height>__MainScreen_Height&&self.tableView.contentSize.height>__MainScreen_Height-44)
        {
            if(!isLoading&&!_isLoadingRefresh)
            {
                alreadyRefresh = NO;
                _isLoadingRefresh = NO;
                [loadingView startAnimating];
                lab.text = NSLocalizedString(@"loadingNotice", nil);
                isLoading = YES;
                segmentController.userInteractionEnabled = NO;
                [self performSelector:@selector(startLoadNextPage) withObject:nil afterDelay:0.5];
            }
            else if(_isLoadingRefresh)
            {
                [loadingView stopAnimating];
                
                lab.text = NSLocalizedString(@"pullLoadMore", nil);
            }
        }
        
        else if(self.tableView.contentSize.height<__MainScreen_Height-44)
        {
            self.tableView.tableFooterView = nil;
        }
    }
}

#pragma mark -
#pragma mark AKSegmentedControlDelegate

- (void)segmentedViewController:(AKSegmentedControl *)segmentedControl touchedAtIndex:(NSUInteger)index
{
    if(index == 1)
    {
        [MyAppDataManager.unReadBroadInfor setValue:@"0" forKey:@"h"];
        [MyAppDataManager.unReadBroadInfor setValue:@"0" forKey:@"g"];
        
    }
    else if(index == 0)
    {
        [MyAppDataManager.unReadBroadInfor setValue:@"0" forKey:@"z"];
    }
    [self updateBroadcastBadgeValue];
    
    if(index!=selectIndex)
    {
        selectIndex = index;
        [self setRefreshing];
    }
    else
    {
        
    }
    
}

//-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
//{
//    NSArray *indexPaths = [self.tableView indexPathsForVisibleRows];
//    NSDictionary *nearDic;
//    NSDictionary *conDic;
//
//    for(NSIndexPath *indexPath in indexPaths)
//    {
//        //图片和语音
//        if(MyAppDataManager.nearDos.count){
//            nearDic= [MyAppDataManager.nearDos objectAtIndex:indexPath.row];
//        }else{
//            nearDic= nil;
//        }
//        NSDictionary *nearDo = [nearDic valueForKey:@"actioninfor"];
//        conDic = [nearDo valueForKey:@"mcontent"];
//        //        NSDictionary *userInfor = [nearDic valueForKey:@"userinfor"];
//
//        _imageContentString = nil;
//        _soundContentString = nil;
//        _soundTimeString = nil;
//
//        BanBu_DigiCell *cell = (BanBu_DigiCell *)[self.tableView cellForRowAtIndexPath:indexPath];
//
//        for(NSDictionary *aDic in [conDic valueForKey:@"attach"]){
//            if([[aDic valueForKey:@"type"] isEqualToString:@"image"]){
//                if(![[aDic valueForKey:@"content"]isEqualToString:@""]){
//                    _imageContentString = [NSString stringWithString:[aDic valueForKey:@"content"]];
//                }
//            }else if([[aDic valueForKey:@"type"] isEqualToString:@"sound"]){
//                if(![[aDic valueForKey:@"content"]isEqualToString:@""]){
//
//                    _soundContentString = [NSString stringWithFormat:@"0,%@",[aDic valueForKey:@"content"]];
//                    if([aDic valueForKey:@"length"]){
//                        _soundTimeString = [NSString stringWithFormat:@"%@\"",[aDic valueForKey:@"length"]];
//
//                    }
//
//                }
//            }
//        }
//        if(_imageContentString){
//
////            [cell setHeadImage:_imageContentString];
//            __block NSString *blockStr = [NSString stringWithString:_imageContentString];
//            [cell.headImageView setImageWithURL:[NSURL URLWithString:_imageContentString] placeholderImage:[UIImage imageNamed:@"photo_default.png"] success:^(UIImage *image){
//                [imageDic  setValue:image forKey:blockStr];
////                [cell.iconButton setImage:image forState:UIControlStateNormal];
//            } failure:^(NSError *error) {
//
//            }];
//            if(_soundContentString){
//                [cell.playButton setTitle:_soundContentString forState:UIControlStateNormal];
//                [cell.playButton setImage:[UIImage imageNamed:@"播放语音_未按下_不空.png"] forState:UIControlStateNormal];
//                cell.soundTimeLabel.text = _soundTimeString;
//            }else{
//                cell.playButton.frame = CGRectZero;
//                cell.soundTimeLabel.frame = CGRectZero;
//            }
//        }
//        else{
//            cell.headImageView.frame = CGRectZero;
//            cell.playButton.frame = CGRectZero;
//            cell.soundTimeLabel.frame = CGRectZero;
//            _headImageViewHeight = 0;
//        }
//        
//    }
//}
@end
